import request from '/@/utils/request';
import { useUrlUtil } from '/@/utils/urlUtil';
import { BaseRequest, BaseResponse } from '/@/interfaces/BaseModel';
import { TaskScriptApi } from '/@/enums/dpp-api-enum';
import {
    TaskScriptSearchParamModel,
    TaskScriptListModel,
    TaskScriptDetailModel,
    TaskScriptAddParamModel,
    TaskScriptEditParamModel,
    TaskScriptDeleteParamModel
} from '/@/interfaces/DataPipelineModel';

function useTaskScript() {
    return {
        list: function (payload: BaseRequest<TaskScriptSearchParamModel>) {
            return request.post<BaseResponse<TaskScriptListModel[]>>(TaskScriptApi.LIST, payload);
        },
        detail: function (payload: Object) {
            const useUrl = useUrlUtil();
            return request.get<BaseResponse<TaskScriptDetailModel>>(useUrl.joinParam(TaskScriptApi.DETAIL, payload));
        },
        add: function (payload: BaseRequest<TaskScriptAddParamModel>) {
            return request.post<BaseResponse<boolean>>(TaskScriptApi.ADD, payload);
        },
        edit: function (payload: BaseRequest<TaskScriptEditParamModel>) {
            return request.post<BaseResponse<boolean>>(TaskScriptApi.EDIT, payload);
        },
        del: function (payload: BaseRequest<TaskScriptDeleteParamModel>) {
            return request.post<BaseResponse<boolean>>(TaskScriptApi.DEL, payload);
        },
    };
}

export default useTaskScript;